import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import*

testCase="DBshop004_购物流程的取消"

# 打开网页
firefox=openBrowser(url)

# 登录账号
DBshopLogin(firefox,userName,password)

# 搜索框搜索小米
firefox.find_element_by_xpath('//input[@name="keywords"]').send_keys('小米')

# 点击搜索按钮
firefox.find_element_by_xpath('//input[@type="submit"]').click()

# 点击小米MIX3图片
firefox.find_element_by_xpath('//a[@href="/dbshop/goods/8/2"]').click()

#切换到第二页面
switchWindow(firefox,2)

# 点击添加到购物车
firefox.find_element_by_id('add_cart_submit').click()
time.sleep(2)

# 点击去购物车结算
firefox.find_element_by_link_text("去购物车结算").click()

# 点击去结算按钮
firefox.find_element_by_link_text("去结算").click()

# 默认收货地址点击下一步
firefox.find_element_by_xpath("//input[@value='下一步']").click()

# 点击余额支付
firefox.find_element_by_xpath("//input[@value='yezf']").click()

# 确认订单
firefox.find_element_by_xpath("//input[@value='确认订单']").click()

#使用变量orderNO存储订单编号
orderNO=firefox.find_element_by_xpath('(//font[@color="color:#ED145B"])[2]').text
rootPath=get_pro_rootpath()
writeFile(rootPath+'\public\order1.txt',orderNO)

# 查看订单详情
firefox.find_element_by_xpath("//input[@value='查看订单详情']").click()

# 点击取消订单
firefox.find_element_by_xpath("//button[text()='取消订单']").click()
firefox.switch_to.alert.accept()

time.sleep(3)

#断言
try:
    firefox.find_element_by_link_text(orderNO).is_displayed()  #is_displayed()函数判断元素是否显示
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)

firefox.quit()
